Problem 1 |
Create a New Project called CardioidAuto to build an appropriate training set for learning of the cardioid r = 1 + cos(θ) using a ANN for auto-association. Use 2000 training cases and 64 inputs. The input training set must include noisy cardioids and the target must include clean cardioids as shown in the figure. The training set must include the same phase in eight different training cases. |
Solution 1 |
After editing the file![]() |
CardioidAuto\BuildTrainSet.lab |
int numCases = 2000; int numInputs = 64; double deltaInput = 6.28/numInputs; double delta = 6.28/(numCases-1); int i; int j; double phase = 0.0; //____________________ trainSetTarget Matrix trainSetTarget ; trainSetTarget .Create(numCases, numInputs); for(i=0; i<numCases; i++) { phase = i*delta; for (j=0; j<numInputs; j++) { trainSetTarget [i][j] = (1.0+cos(j*deltaInput + phase)); } } trainSetTarget .Save(); //____________________ trainSetInput Matrix noise; noise.CreateRandom(numCases, numInputs, 0.0, 2.0); Matrix trainSetInput= 0.9*trainSetTarget + 0.1*noise; trainSetInput.Save(); |
Problem 2 |
Edit the BuilValidSet.lab file to build the validation set using the training set. Contaminate the target training set with 10% of noise to create the input validation set. The target of the validation set is the same as the target of the training set. |
Solution 2 |
After editing the file, ![]() |
CardioidAuto\BuildValidSet.lab |
//_______________________ Load the training set Matrix trainSetTarget; trainSetTarget.Load(); int numRows = trainSetTarget.GetRowCount(); int numCols= trainSetTarget.GetColCount(); Matrix noise; noise.CreateRandom(numRows, numCols, 0.0, 2.0); Matrix validSetInput = 0.9*trainSetTarget + 0.1*noise; validSetInput.Save(); |
Problem 3 |
Edit the Train.lab file to design and train an ANN for the cardioid. Use one hidden layer. Train the ANN using simulated annealing and the conjugate gradient method. Because of the number of outputs, it is not possible to use the method of Levenberg Marquardt. |
Solution 3 |
After editing the file, ![]() |
CardioidAuto\Train.lab |
int numInputs = 64; int i; //_________________________ Network Setup LayerNet net; net.Create(numInputs, 13, 0, numInputs); for(i = 0; i<numInputs; i++) { net.SetInScaler(i, 0, 2); // Input values are from 0 to 2 net.SetOutScaler(i, 0, 2); // Output values are from 0 to 2 } //________________________ Load and set the training set Matrix trainSetInput; trainSetInput.Load(); Matrix trainSetTarget; trainSetTarget.Load(); net.SetTrainSet(trainSetInput, trainSetTarget, false); //________________________ Train net.TrainSimAnneal(10, 20, 15, 0.01, false, 4, 1.0e-12); net.TrainConjGrad(2000,1.0e-12); //_____________________________ Save the trained network net.Save(); |
Problem 4 |
Edit the CheckTraining.lab file to check the training: (a) Compute the mean squared error for the ANN using the training set. (b) Plot the error for each training case. (c) Save the plot as a vector image (checkTraining.pdf and checkTraining.emf) |
Solution 4 (a) |
After editing the file, ![]() |
CardioidAuto\CheckTraining.lab |
//_________________________________________ Load the training set Matrix trainSetInput; trainSetInput.Load(); Matrix trainSetTarget; trainSetTarget.Load(); //_________________________________________ Load the ANN LayerNet net; net.Load(); //_________________________________________ Run Matrix output = net.Run(trainSetInput); double mse = ComputeMse(output, trainSetTarget); //_________________________________________ Relative Error Vector error = ComputeRelError(output, trainSetTarget); XyChart checkTraining; checkTraining.SetCaption("case", false, "Relative Error", false); checkTraining.AddGraphY(error, "Relative Error", 2, 1, 0, 255, 0); checkTraining.SetLogScale(false, true); checkTraining.SetLimits(0, trainSetTarget.GetRowCount(), 1.0e-5, 1.0); checkTraining.SetColorMode(2); checkTraining.SaveAndShow(); checkTraining.SavePDF(0.0); checkTraining.SaveEMF(); |
Problem 5 |
Edit the Validation.lab file to perform the validation of the ANN. (a) Compute the mean squared error for the ANN using the validation set. (b) Plot the error for each validation case. (c) Save the plot as a vector image (validation.pdf and validation.emf) |
Solution 5 (a) |
After editing the file, ![]() |
CardioidAuto\Validation.lab |
//_________________________________________ Load the validation set Matrix validSetInput; validSetInput.Load(); Matrix trainSetTarget; trainSetTarget.Load(); //_________________________________________ Load the ANN LayerNet net; net.Load(); //_________________________________________ Run Matrix output = net.Run(validSetInput); //_________________________________________ Compute the mean squared error double mse = ComputeMse(output, trainSetTarget); //_________________________________________ Relative Error Vector error = ComputeRelError(output, trainSetTarget); XyChart validation; validation.SetCaption("case", false, "Relative Error", false); validation.AddGraphY(error, "Relative Error", 2, 1, 0, 255, 0); validation.SetLogScale(false, true); validation.SetLimits(0, trainSetTarget.GetRowCount(), 1.0e-5, 1.0); validation.SetColorMode(2); validation.SaveAndShow(); validation.SavePDF(0.0); validation.SaveEMF(); |
Problem 6 |
Generate a report in Microsoft Word. Write some conclusions in the report focusing on the problems that were faced during the simulation and how these problems were or could be solved. |